package com.group3.controller.adminController;

import com.group3.controller.Validated.Add;
import com.group3.domain.Lesson;
import com.group3.pojo.receive.TLessonListReceive;
import com.group3.pojo.result.LessonResult;
import com.group3.pojo.Page;
import com.group3.service.ALessonService;
import com.group3.utils.Result;
import com.group3.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * lessonController
 *
 * @author HY
 * 2021/06/03 15:29
 **/

@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admin/lesson")
public class ALessonController {

    @Resource
    private ALessonService aLessonService;

//    管理员增加课程名
    @PostMapping(value = "")
    @ApiOperation(value = "增加课程名")
    @ApiImplicitParam(name = "lessonName", value = "课程名",required = true,
            dataType = "String")
    public Result addLesson(@NotBlank @RequestParam String lessonName){

//        return ResultUtil.success(lessonName);
        return aLessonService.addLesson(lessonName);
    }

    //    管理员删除课程名
    @DeleteMapping(value = "")
    @ApiOperation(value = "删除课程名")
    @ApiImplicitParam(name = "lessonId", value = "课程id",required = true,
            dataType = "Integer")
    public Result deleteLesson(@NotBlank @RequestParam Integer lessonId){

//        return ResultUtil.success(lessonId);
        return aLessonService.deleteLesson(lessonId);
    }

    //    管理员查询课程名
    @GetMapping(value = "")
    @ApiOperation(value = "查询课程名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lessonName", value = "课程名",
                    dataType = "String"),
            @ApiImplicitParam(name = "pageNumber", value = "页码",
                    dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",
                    dataType = "Integer"),
    })
    public Result SelectLesson(
            String lessonName, Page page){

//        return ResultUtil.success(lessonId);
        return aLessonService.SelectLesson(lessonName, page);
    }

    //    管理员增加课程时间安排
    @PostMapping(value = "/Students")
    @ApiOperation(value = "给课程安排添加学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lessonName", value = "课程安排id",required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "studentIds",
                    value = "学生学号集合(第一个集合里面为分组集合，第二个集合为分组内学生的学号)",
                    required = true,
                    dataType = "List<List<String>>"),
    })
    //TODO 可以双重数组取值
    public Result addStudentToLesson(@RequestParam String lessonName,
                                     @RequestParam  String[][] studentIds){

//        return ResultUtil.success(lessonId+"==="+studentIds.toString());
        return aLessonService.addStudentToLesson(lessonName, studentIds);
    }




////    管理员修改课程
//    @PutMapping(value = "")
//    @ApiOperation(value = "修改课程名")
//    @ApiImplicitParams({
//        @ApiImplicitParam(name = "lessonId", value = "课程id",required = true,
//                dataType = "int"),
//        @ApiImplicitParam(name = "lessonName", value = "课程名",required = true,
//                dataType = "String"),
//    })
//    public Result updateLesson(@PathVariable String lessonId){
//
//        Result result = null;
//
//        return result;
//    }


//    根据条件查找课程安排
    @GetMapping(value = "/schudel")
    @ApiOperation(value = "根据条件查找课程安排")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "startDate", value = "开始日期",
                dataType = "Date"),
        @ApiImplicitParam(name = "endDate", value = "结束日期",
                dataType = "Date"),
        @ApiImplicitParam(name = "lessonName", value = "课程名称",
                dataType = "String"),
            @ApiImplicitParam(name = "teacherZ", value = "责任教师",
                dataType = "String"),
            @ApiImplicitParam(name = "teacherS", value = "实训教师",
                dataType = "String"),
    })
    public Result<List<LessonResult>> selectLessonSchedule(TLessonListReceive lessonListReceive){

//        return ResultUtil.success(tLessonListReceive.toString());
        return aLessonService.selectLesson(lessonListReceive);
    };

//    @GetMapping("/selectGroups")
//    @ApiOperation(value = "查找所有学生分组（项目组）")
//    public Result<List<StudentGroup>> selectGroups(){
//
//        Result result = null;
//
//        return result;
//    }

//    管理员修改课程安排信息
    @PutMapping(value = "/schedule")
    @ApiOperation(value = "修改课程安排信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lessonId", value = "课程安排id",required = true,
                    dataType = "int"),
            @ApiImplicitParam(name = "date", value = "上课时间（某一天）",
                    dataType = "Date"),
            @ApiImplicitParam(name = "startTime", value = "应签到时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "应签退时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "classRoom", value = "教室名",
                    dataType = "String"),
            @ApiImplicitParam(name = "remark", value = "备注",
                    dataType = "String")
    })
    public Result updateLesson(Lesson lesson){

//        return ResultUtil.success(lesson.toString());
        return aLessonService.updateLesson(lesson);
    }

//    管理员删除课程安排
    @DeleteMapping(value = "/schedule")
    @ApiOperation(value = "删除课程安排")
    @ApiImplicitParam(name = "lessonId", value = "课程安排id",required = true,
            dataType = "Integer")
    public Result deleteLessonSchedule(Integer lessonId){

//        return ResultUtil.success(lessonId);
        return aLessonService.deleteLesson(lessonId);
    }

//    管理员增加课程时间安排
    @PostMapping(value = "/schedule")
    @ApiOperation(value = "增加课程时间安排")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lessonId", value = "课程安排id",
                    dataType = "String"),
            @ApiImplicitParam(name = "date", value = "上课时间（某一天）",
                    dataType = "Date"),
            @ApiImplicitParam(name = "startTime", value = "应签退时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "应签退时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "classRoom", value = "教室名",
                    dataType = "String"),
            @ApiImplicitParam(name = "remark", value = "备注",
                    dataType = "String")
    })
    public Result addLesson(@Validated(Add.class) Lesson lesson){

//        return ResultUtil.success(lesson.toString());
        return aLessonService.addLesson(lesson);
    }

    //    管理员增加课程时间安排
    @PostMapping(value = "/schedule/copy")
    @ApiOperation(value = "复制课程时间安排")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lessonId", value = "课程安排id",required = true,
                    dataType = "Integer")
    })
    public Result copyLesson(
            @NotEmpty(message = "复制课程的课程id呢？") Integer lessonId){

//        return ResultUtil.success(lesson.toString());
        return aLessonService.copyLesson(lessonId);
    }
}
